package com.bjsxt.userscenters.springmvc.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.bjsxt.userscenters.common.util.ConstatFinalUtil;
import com.bjsxt.userscenters.users.pojo.AAdmins;

@Component("authInterceptor")
public class AuthInterceptor extends HandlerInterceptorAdapter
{
	
	/**
	 * return true:放行 false:拦截
	 */
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception
	{
		String info="";
		
		HttpSession session = request.getSession();
		AAdmins admins = (AAdmins) session.getAttribute("admins");
		if (admins == null)
		{
			/* 登录失败  客户端跳转到登录页面
			 * 先跳转到Controller
			 * */
			/*非法登陆 请先登陆*/
			info=ConstatFinalUtil.INFO_JSON.getString("7");
			session.setAttribute("info", info);
			response.sendRedirect(request.getContextPath()+"/login.do");
			return false;
		}
		/* 登陆成功 */
		return true;
	}

}
